package com.example.testapp.activity.dabastate;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by l on 2016/6/6.
 */
public class DBOpenHelper extends SQLiteOpenHelper {

    private final static int VERSION = 1;

    public DBOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    public DBOpenHelper(Context context, String name) {
        this(context, name, null);
    }

    public DBOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory){
        this(context, name, null, VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE IF NOT EXISTS Calendar(CalendarID integer primary key autoincrement, CalendarTypeID integer, remindID integer, CalendarContent text, CalendarDate text)");
        db.execSQL("CREATE TABLE IF NOT EXISTS CalendarTagDate(TagID integer primary key autoincrement, year integer, month integer, day integer, CalendarID integer)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS Calendar");
        db.execSQL("DROP TABLE IF EXISTS CalendarTagDate");
        onCreate(db);
    }
}
